<%@ include file="/common/taglibs.jsp"%>
<c:set var="configMap" value="${requestScope.configMap}" />
<probiz:pageHeading pageHeadingKey="systemConfigList.title" />
<content tag="buttons">
	<probiz:iconBtn btnType="save" onclick="fnSave()" />
	<probiz:iconBtn btnType="refreshRerverCache" onclick="return fnDoSimpleAction(this,'clearAdminSiteCache');" btnTextKey="button.refreshAdminSiteCache"/>
	<probiz:iconBtn btnType="refreshRerverCache" onclick="return fnDoSimpleAction(this,'clearFrontSiteCache');" btnTextKey="button.refreshFrontSiteCache"/>
</content>

<%-- 
<%@include file="./include/testConfigForm.jspf" %>
--%>
<c:set var="configMap" value="${requestScope.configMap}" />

<div class="cnt">
	<div class="top clearfix">
		<ul class="tab" id="detail">
			<li class="curr"><a href="#foundation"><span><fmt:message key="systemConfig.basicSettings"/></span></a></li>
			<li style="display:none;"><a href="#sales"><span><fmt:message key="systemConfig.set.shoppingAndOrder"/></span></a></li>
			<li><a href="#product"><span><fmt:message key="systemConfig.set.product"/></span></a></li>
			<li style="display:none;"><a href="#customer"><span><fmt:message key="systemConfig.set.customers"/></span></a></li>
			<li style="display:none;"><a href="#email"><span><fmt:message key="systemConfig.set.Email"/></span></a></li>
			<li><a href="#system"><span><fmt:message key="systemConfig.set.security"/></span></a></li>
			<li style="display:none;"><a href="#plugin"><span><fmt:message key="systemConfig.set.pluginUnit"/></span></a></li>
		</ul>
	</div>
	<div class="modify">
		<form class="mainForm" name="configForm" id="configForm" method="post">
			<input type="hidden" name="doAction" value="save" />
			<div id="foundation">
				<%@include file="./include/foundationConfigForm.jspf" %>
			</div>
			<div id="sales">
				<%@include file="./include/salesConfigForm.jspf" %>
			</div>
			<div id="product">
				<%@include file="./include/productConfigForm.jspf" %>
			</div>
			<div id="customer">
				<%@include file="./include/customerConfigForm.jspf" %>
			</div>
			<div id="email">
				<%@include file="./include/emailConfigForm.jspf" %>
			</div>
			<div id="system">
				<%@include file="./include/systemConfigForm.jspf" %>
			</div>
			<div id="plugin">
				<%@include file="./include/pluginConfigForm.jspf" %>
			</div>
		</form>
	</div>
	<probiz:ui_tabs tabsId="detail" />
</div>


<script type="text/javascript">

$j(document).ready(function(){
	autoApplyValidate($('configForm'));
	
	<%--基础设置--%>
	$j("[name='isAdminApplicationIsolate'][value='${configMap['isAdminApplicationIsolate']}']").attr("checked", "true");
	$j("[name='isOpenFulltextSearch'][value='${configMap['isOpenFulltextSearch']}']").attr("checked", "true");
	$j("[name='isOpenCasService'][value='${configMap['isOpenCasService']}']").attr("checked", "true");
	<%--购物与订单--%>
	$j("[name='isOpenFrontOrder'][value='${configMap['isOpenFrontOrder']}']").attr("checked", "true");
	$j("[name='isAnonymousCheckoutEnabled'][value='${configMap['isAnonymousCheckoutEnabled']}']").attr("checked", "true");
	$j("[name='isInvoiceSupported'][value='${configMap['isInvoiceSupported']}']").attr("checked", "true");
	$j("[name='isSupportWrapExpress'][value='${configMap['isSupportWrapExpress']}']").attr("checked", "true");
	$j("[name='isShopPointPaymentEnabled'][value='${configMap['isShopPointPaymentEnabled']}']").attr("checked", "true");
	<%--商品设置--%>
	$j("[name='isRecentViewEnabled'][value='${configMap['isRecentViewEnabled']}']").attr("checked", "true");
	<%--客户设置--%>
	$j("[name='isAnonymousNewsSubscriptionEnabled'][value='${configMap['isAnonymousNewsSubscriptionEnabled']}']").attr("checked", "true");
	$j("[name='isOpenOnlineService'][value='${configMap['isOpenOnlineService']}']").attr("checked", "true");
	<%--邮件设置--%>
	<c:if test="${configMap['mail.auth'] == 'true'}">
		$j("#needAuth").attr("checked", "checked");
	</c:if>
	<c:if test="${configMap['mail.tlsEnable'] == 'true'}">
		$j("#tlsEnable").attr("checked", "checked");
	</c:if>
	$j("[name='mail.disableQueue'][value='${configMap['mail.disableQueue']}']").attr("checked", "true");
	showOrHideAuthConfig();
	showOrHideQueueConfig();
	<%--性能与安全--%>
	$j("[name='isRememberMeEnabled'][value='${configMap['isRememberMeEnabled']}']").attr("checked", "true");
	$j("[name='isValidationCodeEnabled'][value='${configMap['isValidationCodeEnabled']}']").attr("checked", "true");	
	
	$j("[name='isOpenMsgSend'][value='${configMap['isOpenMsgSend']}']").attr("checked", "true");
	$j("[name='isAnalyticsDisabled'][value='${configMap['isAnalyticsDisabled']}']").attr("checked", "true");
	
	<%--禁用状态，跟踪代码可为空--%>
	<c:choose>
		<c:when test="${configMap['isAnalyticsDisabled']}">
			applyValidate($("analyticsCode"),"required,maxlength=1000");
		</c:when>
		<c:otherwise>
			applyValidate($("analyticsCode"),"maxlength=1000");
		</c:otherwise>
	</c:choose>
	$j("[name='isAnalyticsDisabled']").bind("click",function(){
		if(this.value == 'true'){
			applyValidate($("analyticsCode"),"required,maxlength=1000");
		}else{
			applyValidate($("analyticsCode"),"maxlength=1000");
		}
		validateField($("analyticsCode"));
	});
	
	<%--禁用状态,短信账号、密码可为空--%>
	<c:choose>
		<c:when test="${configMap['isOpenMsgSend']}">
			applyValidate($("serialNo"),"required,maxlength=100");
			applyValidate($("serialNoPassWord"),"required,maxlength=20");
			applyValidate($("smsBatchSendCount"),"required,number");
			applyValidate($("smsMaxSendTimes"),"required,number");
		</c:when>
		<c:otherwise>
			applyValidate($("serialNo"),"maxlength=100");
			applyValidate($("serialNoPassWord"),"maxlength=20");
			applyValidate($("smsBatchSendCount"),"number");
			applyValidate($("smsMaxSendTimes"),"number");
		</c:otherwise>
	</c:choose>

	$j("[name='isOpenMsgSend']").bind("click",function(){
		if(this.value == 'true'){
			applyValidate($("serialNo"),"required,maxlength=100");
			applyValidate($("serialNoPassWord"),"required,maxlength=20");
			applyValidate($("smsBatchSendCount"),"required,number");
			applyValidate($("smsMaxSendTimes"),"required,number");
		}else{
			applyValidate($("serialNo"),"maxlength=100");
			applyValidate($("serialNoPassWord"),"maxlength=20");
			applyValidate($("smsBatchSendCount"),"number");
			applyValidate($("smsMaxSendTimes"),"number");
		}
		validateField($("serialNo"));
		validateField($("serialNoPassWord"));
		validateField($("smsBatchSendCount"));
		validateField($("smsMaxSendTimes"));
	});
	
	<%--自动触发一次当前选中状态的事件--%>
	$j("[name='isAnalyticsDisabled'][@checked]").trigger("click");
	$j("[name='isOpenMsgSend'][@checked]").trigger("click");
	
	<%--快递100--%>
	$j("#kuaidi100Type").change(function(){
		if(this.value == "2"){
			$j("#kuaidi100IdKeyTr").show();
			applyValidate($("kuaidi100IdKey"),"required");
		}else{
			$j("#kuaidi100IdKeyTr").hide();
			removeValidate($("kuaidi100IdKey"));
		}
	});
})

//显示或隐藏邮件验证配置
function showOrHideAuthConfig() {
	var i = $j("#needAuth:checked").length;
	if (i > 0) {
		$j("#username").attr("validconf", "required");
		$j("#password").attr("validconf", "required");
		$j("#trUsername").show();
		$j("#trPassword").show();
	} else {
		$j("#username").removeAttr("validconf");
		$j("#password").removeAttr("validconf");
		$j("#trUsername").hide();
		$j("#trPassword").hide();
	}
}

//显示或隐藏邮件队列配置
function showOrHideQueueConfig() {
	var disabled = $j("[name='mail.disableQueue']:checked").val();
	if (disabled == 'true') {
		$j("[name*='queueConfigs']").hide();
	} else {
		$j("[name*='queueConfigs']").show();
	}
}


function showMoreSecurityOptions() {
	$j("#btnShowMoreSecurityOption").hide();
	$j("[name*='moreSecurityOptions']").show();
}

function hideMoreSecurityOptions() {
	$j("#btnShowMoreSecurityOption").show();
	$j("[name*='moreSecurityOptions']").hide();
}
	
function showMoreEmailOptions() {
	$j("#btnShowMoreEmailOption").hide();
	$j("[name*='moreEmailOptions']").show();
}

function hideMoreEmailOptions() {
	$j("#btnShowMoreEmailOption").show();
	$j("[name*='moreEmailOptions']").hide();
}

function fnSave(){
	var frm = $("configForm");
	if (validateForm(frm)) {
		 if (confirm(__FMT.common_message_confirmSave)) {
		 	frm.submit();
		 }
	}else{
		focusOnInvalidTab();
		jAlert(__vaMsg.notPass);
	}
}

//====================短信账号操作=========================
function fnDoSmsLogin() {
	showLoading(1)
	var url = __ctxPath + "/tool/smsQueue.html?doAction=smsLogin";
	var paraData = {};
	$j.post(url, paraData, smsLoginCallback,"json");
}
function smsLoginCallback(data){
	showLoading(2)
	var titles = "短信账号：" + data.serialNo + "\n账号密码：" + data.password;
	var alt = "";
	if (data.status==0) {
		alt = "注册成功！";
	} else if (data.status==10000) {
		alt = "注册失败：连接超时！";
	} else {
		alt = "注册失败：请查检短信账号或余额是否正常！";
	}
	jAlert(titles + "\n" + alt);
}

function fnDoSmsLogout() {
	showLoading(1)
	var url = __ctxPath + "/tool/smsQueue.html?doAction=smsLogout";
	var paraData = {};
	$j.post(url, paraData, smsLogoutCallback,"json");
}
function smsLogoutCallback(data){
	showLoading(2)
	var titles = "短信账号：" + data.serialNo + "\n账号密码：" + data.password;
	var alt = "";
	if (data.status==0) {
		alt = "注消成功！";
	} else if (data.status==10000) {
		alt = "注消失败：连接超时！";
	} else {
		alt = "注消失败：请查检短信账号或余额是否正常！";
	}
	jAlert(titles + "\n" + alt);
}

function fnDoSmsBalance() {
	showLoading(1)
	var url = __ctxPath + "/tool/smsQueue.html?doAction=smsBalance";
	var paraData = {};
	$j.post(url, paraData, smsBalanceCallback,"json");
}
function smsBalanceCallback(data){
	showLoading(2)
	var titles = "短信账号：" + data.serialNo + "\n账号密码：" + data.password;
	var alt = "账号余额："+ data.balance;
	jAlert(titles + "\n" + alt);

}

function showLoading(flag){
	if (flag == 1) {
		$j("#smsCnfigDetail").hide();
		$j("#smsCnfigLoading").show();
	} else {
		$j("#smsCnfigDetail").show();
		$j("#smsCnfigLoading").hide();
	}
}
</script>


	
	



